home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / PASCAL / BIGLDSW.ZIP / TUTOR3.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1996-07-28  |  1.9 KB  |  70 lines

  1. {
  2.   TUTOR2.PAS
  3.  
  4.   This example shows, how to extract files from a BigFile.
  5.  
  6. }
  7.  
  8. uses crt, _BigLoad;
  9.  
  10. const
  11.   Stream1 : byte = 1;
  12.  
  13. procedure ExtractFileFromBigFile( Stream : Byte; FromFileName : String;
  14.                                                  ToFileName   : String );
  15. var
  16.   Buffer : array[1..512] of byte;
  17.   ToF    : file;
  18.   NumRead,
  19.   NumWritten : Word;
  20. begin
  21.   { open a file for reading from the BigFile by the stream Stream1 and
  22.     reset it. The second parameter of BigReset has NO effect on any
  23.     procedures or functions of BigLoad. It exists just to make it easier
  24.     to convert your routines to BigFile-compatible ones. }
  25.   BigAssign( Stream, FromFileName );
  26.   BigReset( Stream, 1 );
  27.  
  28.   { Open output file }
  29.   Assign(ToF, ToFileName );
  30.   { Record size = 1 }
  31.   Rewrite(ToF, 1);
  32.  
  33.   { now copy it }
  34.   Writeln('Copying ', BigFileSize( Stream ), ' bytes...');
  35.   repeat
  36.  
  37.     { reads from the stream Stream to Buffer; NumRead contains the
  38.       Number of really readed bytes }
  39.     BigBlockRead( Stream, Buffer, SizeOf(Buffer), NumRead);
  40.  
  41.     { write the buffer of the size NumRead to disk }
  42.     BlockWrite( ToF, Buffer, NumRead, NumWritten );
  43.  
  44.   until (NumRead = 0) or (NumWritten <> NumRead);
  45.     { stop, if we had read 0 bytes (EOF occured) or if we wrote an unequal
  46.       number bytes to disk as we read (disk is full). }
  47.  
  48.  
  49.   { close stream Stream of the BigFile }
  50.   BigClose( Stream );
  51.  
  52.   { Close output file }
  53.   Close(ToF);
  54. end;
  55.  
  56. begin
  57.   ClrScr;
  58.  
  59.   { open the BigFile "TESTBIG" and handle the index from disk. You may also
  60.     try to hanlde the index from memory with IndexFromMemory }
  61.   BigFileInit( 'TESTBIG', IndexFromDisk );
  62.  
  63.   { now extract the File MAKEBIG.EXE from BigFile and save it under the
  64.     file name EXTRACT.EXE }
  65.   ExtractFileFromBigFile( Stream1, 'MAKEBIG.EXE', 'EXTRACT.EXE' );
  66.  
  67.   { close reading from the BigFile }
  68.   BigFileClose;
  69. end.
  70.